import common from './common'
import paths from './paths'

const path = {
  getAllRealms: 'orup/realm/getAllRealms',
  getOrgsOfRealmByGuid: '/orup/org/getOrgsOfRealmByGuid',
  listAllOrgTree: '/orup/org/listAllOrgTree',
  getIssuingOrganizationMap: '/issuing/organization/getIssuingOrganizationMap',
  saveIssuingOrganizationMap: '/issuing/organization/saveIssuingOrganizationMap',
  saveIssuingOrganizationExtendMap: '/issuing/organization/saveIssuingOrganizationExtendMap',
  getIssuingOrganizationExtendMap: '/issuing/organization/getIssuingOrganizationExtendMap',
  updateIssuingOrganizationMap: '/issuing/organization/updateIssuingOrganizationMap',
  listManagedRealmsOfUser: 'orup/realm/listManagedRealmsOfUser',
  interface: {
    projectQuery: '/project/management/list/query',
    projectOverview: '/project/management/overview',
    projectInterfaceTreeQuery: '/project/interface/group/tree/query'
  },
  messageCenter: {
    nameAdd: '/mq/namesrv/add',
    nameQuery: '/mq/namesrv/list/query',
    updateUseTLS: '/mq/namesrv/updateUseTLS',
    updateUseVIPChannel: '/mq/namesrv/updateUseVIPChannel',

    colonyClusterListQuery: '/mq/broker/cluster/list/query',
    colonyQuery: '/mq/broker/config/query',
    colonyUpdate: '/mq/broker/config/update',
    colonyInit: '/mq/broker/init',
    colonyBrokerListQuery: '/mq/broker/list/query',

    topicDelete: '/mq/topic/delete',
    topicQuery: '/mq/topic/list/query',
    topicSend: '/mq/topic/message/send',
    topicRouteQuery: '/mq/topic/route/query',
    topicSave: '/mq/topic/save',
    topicStateQuery: '/mq/topic/stats/query',
    topicTypeListQuery: '/mq/topic/type/list/query',
    topicUpdate: '/mq/topic/update',

    consumerListQuery: '/mq/consumer/list/query',
    consumerGroupListQuery: '/mq/consumer/group/list/query',
    consumerGroupDelete: '/mq/consumer/group/delete',
    consumerOnline: '/mq/consumer/online',
    consumerOffline: '/mq/consumer/offline',
    consumerRestart: '/mq/consumer/restart'
  },
  system: {
    orgManageChildListQuery: '/organization/management/children/list/query',
    orgManageDelete: '/organization/management/delete',
    orgManageGet: '/organization/management/get',
    orgManageListQuery: '/organization/management/list/query',
    orgManageSave: '/organization/management/save',
    orgManageTreeQuery: '/organization/management/tree/query',
    orgManageUpdate: '/organization/management/update',

    orgUserAdd: '/organization/user/management/add',
    orgUserListQuery: '/organization/user/management/list/query',
    orgUserTreeQuery: '/organization/user/management/tree/query',

    roleGroupManageAdd: '/role/group/management/addRoleGroup',
    roleGroupManageDelete: '/role/group/management/deleteRoleGroup',
    roleGroupManageUpdate: '/role/group/management/updateRoleGroup',

    roleManageAdd: 'role/management/addRole',
    roleManageDelete: 'role/management/deleteRole',
    roleManageUpdate: 'role/management/updateRole',

    roleUserManageAdd: '/role/user/management/add',

    permissionManageAdd: '/permission/management/add',
    permissionManageDelete: '/permission/management/delete',
    permissionManageGet: '/permission/management/get',
    permissionManageTreeQuery: '/permission/management/tree/query',
    permissionManageUpdate: '/permission/management/update',

    userManageDelete: '/user/management/delete',
    userManageListQuery: '/user/management/list/query',
    userManageSave: '/user/management/save',
    userManageUpdate: '/user/management/update',
    userManageStateListQuery: '/user/management/state/list/query',

    userPermissionManageAdd: '/user/permission/management/add',
    userPermissionManageListQuery: '/user/permission/management/list/query',
    userPermissionManageBusinessAdd: '/user/permission/management/business/add',
    userPermissionManageDataAdd: '/user/permission/management/data/add',
    userPermissionManageTreeBusinessQuery: '/user/permission/management/tree/business/query',
    userPermissionManageTreeDataQuery: '/user/permission/management/tree/data/query',
    userPermissionManageTreeQuery: '/user/permission/management/tree/query'
  }
}
const orupService = {};

(function (service) {
    service.getCurrentUser = function () {
        return common.get(paths.orup.getCurrentUser)
    }

    service.listRoleByUserId = function (userId) {
        return common.get(paths.orup.listRoleByUserId, { userId: userId })
    }

    service.getUserUnit = function (type, loginName) {
        return common.get(paths.orup.getUserUnit, { type: type, loginName: loginName })
    }

    service.getUserFirstUnit = function (type, loginName) {
        return common.get(paths.orup.getUserFirstUnit, { type: type, loginName: loginName })
    }

    service.changePassword = function (params) {
      return common.get(paths.orup.changePassword, params)
    }

    service.updateMobilephone = function (params) {
      return common.get(paths.orup.updateMobilephone, params)
    }

    service.getOrgTreeWithUser = function (params, data) {
      return common.post(paths.orup.getOrgTreeWithUser, params, data)
    }

    service.saveUserAgent = function (params, data) {
      return common.post(paths.agent.saveUserAgent, params, data)
    }

    service.deleteUserAgent = function (params) {
      return common.get(paths.agent.deleteUserAgent, params)
    }

    service.getUserAgentById = function (params) {
      return common.get(paths.agent.getUserAgentById, params)
    }

    service.getUserAgentList = function (params) {
      return common.get(paths.agent.getUserAgentList, params)
    }

    service.searchUserAgent = function (params, data) {
      return common.post(paths.agent.searchUserAgent, params, data)
    }

    service.getAllRealms = function () {
      return common.get(path.getAllRealms, {})
    }

    service.getOrgsOfRealmByGuid = function (realmGuid) {
      return common.get(path.getOrgsOfRealmByGuid, { realmGuid: realmGuid })
    }

    service.listAllOrgTree = function (realmGuid) {
      return common.get(path.listAllOrgTree, { realmGuid: realmGuid })
    }

    service.getIssuingOrganizationMap = function (params) {
      return common.post(path.getIssuingOrganizationMap, params, null)
    }

    service.saveIssuingOrganizationMap = function (data) {
      return common.post(path.saveIssuingOrganizationMap, null, data)
    }

    service.saveIssuingOrganizationExtendMap = function (params, data) {
      return common.post(path.saveIssuingOrganizationExtendMap, params, data)
    }

    service.getIssuingOrganizationExtendMap = function (params) {
      return common.get(path.getIssuingOrganizationExtendMap, params)
    }

    service.updateIssuingOrganizationMap = function (data) {
      return common.post(path.updateIssuingOrganizationMap, null, data)
    }

    service.listManagedRealmsOfUser = function (userId) {
      return common.get(path.listManagedRealmsOfUser, { userId: userId })
    }

    service.projectQuery = function (params) {
      return common.post(path.interface.projectQuery, null, params)
    }

    service.projectOverview = function (params) {
      return common.post(path.interface.projectOverview, params, null)
    }

    service.projectInterfaceTreeQuery = function (data) {
      return common.post(path.interface.projectInterfaceTreeQuery, null, data)
    }

    service.nameAdd = function (nameServerAddress) {
      return common.post(path.messageCenter.nameAdd, { nameServerAddress: nameServerAddress }, null)
    }

    service.nameQuery = function () {
      return common.get(path.messageCenter.nameQuery, {})
    }

    service.updateUseTLS = function (params) {
      return common.post(path.messageCenter.updateUseTLS, params, null)
    }

    service.updateUseVIPChannel = function (params) {
      return common.post(path.messageCenter.updateUseVIPChannel, params, null)
    }

    service.colonyClusterListQuery = function () {
      return common.get(path.messageCenter.colonyClusterListQuery, {})
    }

    service.colonyBrokerListQuery = function (id) {
      return common.get(path.messageCenter.colonyBrokerListQuery, { brokerClusterId: id })
    }

    service.topicQuery = function (topicType, topicName) {
      return common.get(path.messageCenter.topicQuery, { topicType: topicType, topicName: topicName }, null)
    }

    service.topicTypeListQuery = function () {
      return common.get(path.messageCenter.topicTypeListQuery, {})
    }

    service.topicSave = function (data) {
      return common.post(path.messageCenter.topicSave, null, data)
    }

    service.topicDelete = function (data) {
      return common.post(path.messageCenter.topicDelete, null, data)
    }

    service.consumerListQuery = function (data) {
      return common.post(path.messageCenter.consumerListQuery, null, data)
    }

    service.consumerGroupListQuery = function (data) {
      return common.post(path.messageCenter.consumerGroupListQuery, null, data)
    }

    service.consumerGroupDelete = function (id) {
      return common.post(path.messageCenter.consumerGroupDelete, null, { consumerGroupId: id })
    }

    service.consumerOnline = function (id) {
      return common.post(path.messageCenter.consumerOnline, { consumerId: id }, null)
    }

    service.consumerOffline = function (id) {
      return common.post(path.messageCenter.consumerOffline, { consumerId: id }, null)
    }

    service.consumerRestart = function (id) {
      return common.post(path.messageCenter.consumerRestart, { consumerId: id }, null)
    }

    service.orgManageChildListQuery = function (id) {
      return common.get(path.system.orgManageChildListQuery, { parentId: id }, null)
    }

    service.orgManageDelete = function (data) {
      return common.post(path.system.orgManageDelete, null, data)
    }

    service.orgManageGet = function (id) {
      return common.get(path.system.orgManageGet, { organizationId: id }, null)
    }

    service.orgManageListQuery = function (data) {
      return common.post(path.system.orgManageListQuery, null, data)
    }

    service.orgManageSave = function (data) {
      return common.post(path.system.orgManageSave, null, data)
    }

    service.orgManageTreeQuery = function (data) {
      return common.post(path.system.orgManageTreeQuery, null, data)
    }

    service.orgManageUpdate = function (data) {
      return common.post(path.system.orgManageUpdate, null, data)
    }

    service.orgUserAdd = function (id, data) {
      return common.post(path.system.orgUserAdd, { organizationId: id }, data)
    }

    service.orgUserListQuery = function (data) {
      return common.post(path.system.orgUserListQuery, null, data)
    }

    service.orgUserTreeQuery = function () {
      return common.post(path.system.orgUserTreeQuery)
    }

    service.roleGroupManageAdd = function (data) {
      return common.post(path.system.roleGroupManageAdd, null, data)
    }

    service.roleGroupManageDelete = function (data) {
      return common.post(path.system.roleGroupManageDelete, null, data)
    }

    service.roleGroupManageUpdate = function (data) {
      return common.post(path.system.roleGroupManageUpdate, null, data)
    }

    service.roleManageAdd = function (data) {
      return common.post(path.system.roleManageAdd, null, data)
    }

    service.roleManageDelete = function (data) {
      return common.post(path.system.roleManageDelete, null, data)
    }

    service.roleManageUpdate = function (data) {
      return common.post(path.system.roleManageUpdate, null, data)
    }

    service.roleUserManageAdd = function (id, data) {
      return common.post(path.system.roleUserManageAdd, { roleId: id }, data)
    }

    service.permissionManageAdd = function (data) {
      return common.post(path.system.permissionManageAdd, null, data)
    }

    service.permissionManageDelete = function (data) {
      return common.post(path.system.permissionManageDelete, null, data)
    }

    service.permissionManageGet = function (id) {
      return common.get(path.system.permissionManageGet, { permissionId: id }, null)
    }

    service.permissionManageTreeQuery = function (data) {
      return common.post(path.system.permissionManageTreeQuery, null, data)
    }

    service.permissionManageUpdate = function (data) {
      return common.post(path.system.permissionManageUpdate, null, data)
    }

    service.userManageDelete = function (data) {
      return common.post(path.system.userManageDelete, null, data)
    }

    service.userManageListQuery = function (data) {
      return common.post(path.system.userManageListQuery, null, data)
    }

    service.userManageSave = function (orgId, data) {
      return common.post(path.system.userManageSave, { organizationId: orgId }, data)
    }

    service.userManageUpdate = function (data) {
      return common.post(path.system.userManageUpdate, null, data)
    }

    service.userManageStateListQuery = function () {
      return common.post(path.system.userManageStateListQuery)
    }

    service.userPermissionManageAdd = function (params) {
      return common.post(path.system.userPermissionManageAdd, params, null)
    }

    service.userPermissionManageListQuery = function (data) {
      return common.post(path.system.userPermissionManageListQuery, null, data)
    }

    service.userPermissionManageBusinessAdd = function (params) {
      return common.post(path.system.userPermissionManageBusinessAdd, params, null)
    }

    service.userPermissionManageDataAdd = function (params) {
      return common.post(path.system.userPermissionManageDataAdd, params, null)
    }

    service.userPermissionManageTreeBusinessQuery = function (id) {
      return common.get(path.system.userPermissionManageTreeBusinessQuery, { userId: id }, null)
    }

    service.userPermissionManageTreeDataQuery = function (id) {
      return common.get(path.system.userPermissionManageTreeDataQuery, { userId: id }, null)
    }

    service.userPermissionManageTreeQuery = function (id) {
      return common.get(path.system.userPermissionManageTreeQuery, { userId: id }, null)
    }
})(orupService)

export default orupService
